﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace pTools.PrintTable
{
    public class DataTable_ForPrint : DataTable
    {
        public List<string> Columns { get; set; }
        public List<KVP_Container> Datas { get; set; }
        public DataTable GetPrintTable()
        {
            var dt = new DataTable();
            foreach (var colName in Columns)
            {
                dt.Columns.Add(colName);
            }
            foreach (var container in Datas)
            {
                var row = dt.NewRow();
                foreach (var kvp in container.kvps)
                {
                    if (Columns.Contains(kvp.Key))
                    {
                        row[kvp.Key] = kvp.Value;
                    }
                }
                dt.Rows.Add(row);
            }
            return dt;
        }
    }

    public class KVP
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }

    public class KVP_Container
    {
        public List<KVP> kvps { get; set; }
    }
}
